home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / toadnt11.zip / TOADNT.ASM < prev    next >
Assembly Source File  |  1991-08-27  |  5KB  |  234 lines

  1. ;Toad Hall's NETTIME v1.1            27 August 1991
  2. ;
  3. ;Usage:  NETTIME d:
  4. ;  where "d:" is a network drive on a remote file server.
  5. ;
  6. ;NETTIME then sets your local system to the server's system time.
  7. ;
  8.  
  9. CSEG    SEGMENT    PUBLIC PARA 'CSEG'
  10.     ASSUME    CS:CSEG,DS:CSEG,ES:CSEG
  11.  
  12. CR    EQU    0DH
  13. LF    EQU    0AH
  14.  
  15.     org    80H
  16. cmdlen    db    ?
  17.     db    ?
  18. cmd_word dw    ?        ;first 2 chars on cmdline
  19.  
  20.     org    100H
  21.  
  22. NetTime    PROC    NEAR
  23.     mov    ax,cmd_word        ;first 2 chars on cmdline ('F:')
  24.     cmp    ah,':'            ;it had better be a drive parm
  25.     jnz    Usage            ;dummy
  26.     and    al,0DFH            ;uppercase
  27.     cmp    al,'C'            ;'C'..'Z' are acceptable
  28.     jb    Usage
  29.     cmp    al,'Z'
  30.     jbe    Parm_Ok            ;ok
  31.  
  32. Usage:    mov    dx,offset usage$    ;'Usage: ...'
  33.     mov    al,0FH            ;ERRORLEVEL 15, 'Invalid drive spec'
  34.     jmp    Msg_Term        ;display, die
  35.  
  36. Parm_Ok:
  37.     mov    fpath,al        ;stuff drive char in path name
  38.  
  39.     mov    dx,offset fpath        ;DS:DX -> path name
  40.     xor    cx,cx            ;normal file attrib
  41.     mov    ah,5AH            ;create temp file
  42.     int    21H
  43.     jnc    Create_Ok        ;fine
  44.      mov    dx,offset create$    ;'Create failed'
  45.      jmp    Msg_Term        ;display, die
  46.  
  47. Create_Ok:
  48.  
  49. ;We have to close the temp file
  50. ;or it won't get posted with a date/time.
  51.  
  52.     mov    bx,ax            ;temp file handle into bx
  53.     mov    ah,3EH            ;close that file
  54.     int    21H
  55.     jc    Close_Fail        ;failed (shared code)
  56.  
  57. ;DX points to new temp filename.
  58.  
  59. ;We have to open that temp file
  60. ;before we can read its date/time.
  61.  
  62.     mov    ax,3D00H        ;Open an existing file
  63.     int    21H            ;(that same temp file)
  64.     jnc    Open_Ok            ;fine
  65.      mov    dx,offset open$        ;'Open failed'
  66.      jmp    short Msg_Term        ;display, die
  67.  
  68. Open_Ok:
  69.     mov    bx,ax            ;handle into BX
  70.     mov    ax,5700H        ;Read file date/time
  71.     int    21H            ;date in DX, time in CX
  72.  
  73. ;CX = hour * 2048 + minute * 32 + second /2
  74. ;DX = (year - 1980) * 512 + month * 32 + day
  75.  
  76.     push    dx            ;save file date a sec
  77.  
  78. ;First set system time per file time:
  79.  
  80.     mov    ax,cx            ;time
  81.     call    GetTime            ;convert into CX and DX
  82.     mov    ah,2DH            ;set time
  83.     int    21H
  84.  
  85.     pop    ax            ;file date
  86.     call    GetDate            ;convert into CX and DX
  87.     mov    ah,2BH            ;set date
  88.     int    21H
  89.  
  90.     mov    ah,3EH            ;close the open file
  91.     int    21H
  92.     jnc    Close_Ok
  93. Close_Fail:
  94.      mov    dx,offset close$    ;'Close failed'
  95.      jmp    short Msg_Term        ;display, die
  96.  
  97. Close_Ok:
  98.     mov    dx,offset fpath        ;temp file path/name
  99.     mov    ah,41H            ;delete file
  100.     int    21H
  101.     jnc    Delete_Ok        ;fine
  102.      mov    dx,offset delete$    ;'Delete failed
  103.      jmp    short Msg_Term        ;display, die
  104.  
  105. Delete_Ok:
  106.     mov    dx,offset done$    ;'Complete'
  107.     
  108. ;Arrive here with msg offset in DX,
  109. ;ERRORLEVEL in AL.
  110. Msg_Term:
  111.     push    ax        ;save ERRORLEVEL in AL
  112.  
  113.     cmp    dx,offset create$    ;not a real error?
  114.     jb    Msg_Term1        ;yep (usage or complete)
  115.  
  116.     push    dx            ;save specific error msg
  117.     mov    dx,offset temp$        ;'Network temp file '
  118.     mov    ah,9            ;display msg
  119.     int    21H
  120.     pop    dx            ;specific error msg
  121.     mov    ah,9            ;display msg
  122.     int    21H
  123.     mov    dx,offset failed$    ;' failed',CR,LF
  124.  
  125. Msg_Term1:
  126.     mov    ah,9            ;display final msg
  127.     int    21H
  128.     pop    ax            ;restore ERRORLEVEL
  129.  
  130.     mov    ah,4CH            ;terminate process
  131.     int    21H
  132.  
  133. NetTime    ENDP
  134.  
  135. copyright db    'Copyright (c) 1991 David P Kirschbaum',CR,LF
  136.       db    'All rights reserved',CR,LF,0
  137.  
  138. usage$    db    "Toad Hall's NETTIME",CR,LF
  139.     db    'Usage:  NETTIME d:',CR,LF
  140.     db    'where "d:" is a network drive on a remote file server',CR,LF
  141.     db    "NETTIME then sets your local system to the server's time.",CR,LF
  142.     db    'Commercial license required for distribution.'
  143.     db    CR,LF,'$'
  144.  
  145. done$    db    'System time updated.',CR,LF,'$'
  146.  
  147. temp$    db    'Network temp file $'
  148. create$    db    'create$'
  149. open$    db    'open$'
  150. close$    db    'close$'
  151. delete$    db    'delete$'
  152. failed$    db    ' failed.',CR,LF,'$'
  153.  
  154.  
  155. ; Format the date
  156.  
  157. ;Enter with packed date in AX.
  158. ;Return CX and DX loaded with date
  159. ;per Svc 2BH requirements
  160. ;CX = year (1980-2099)
  161. ;DH = month
  162. ;DL = day
  163.  
  164. Date    Record    Yr:7,Mo:4,Dy:5        ;Packed    date
  165.  
  166. GetDate    PROC    NEAR
  167.     push    bx            ;save BX
  168.  
  169.     mov    bx,ax            ;Save date
  170.     and    AX,Mask    Yr        ;Get year part
  171.     mov    CL,Yr            ;Bits to shift
  172.     shr    ax,cl            ;year
  173.     add    ax,1980            ;add in the '1980'        v1.1
  174.     push    ax            ;save it on the stack a sec
  175.  
  176.     mov    ax,bx            ;Get the date back
  177.     and    AX,Mask    Mo        ;Get month part
  178.     mov    CL,Mo            ;Bits to shift
  179.     shr    ax,cl            ;month
  180.     mov    dh,al            ;DH needs month
  181.  
  182.     mov    ax,bx            ;Get the date back
  183.     and    AX,Mask    Dy        ;Get day part
  184.     mov    CL,Dy            ;Bits to shift
  185.     shr    ax,cl            ;day
  186.     mov    dl,al            ;DL needs day
  187.     pop    cx            ;CX needs year
  188.  
  189.     pop    bx            ;restore
  190.     ret
  191. GetDate    ENDP
  192.  
  193. ;    Format the time
  194.  
  195. ;Enter with packed time in AX.
  196. ;Return CX and DX per DOS Svc 2DH requirements
  197. ;CL=minutes
  198. ;CH=hours
  199. ;DL=hundredths of seconds
  200. ;DH=seconds
  201.  
  202. Time    Record    Hour:5,Min:6,Sec:5    ;Packed    time
  203.  
  204. GetTime    PROC    NEAR
  205.     push    bx            ;save a tick
  206.     mov    bx,ax            ;BX holds packed time
  207.  
  208.     and    AX,Mask    Hour        ;Get hour part
  209.     mov    CL,Hour            ;Bits to shift
  210.     shr    AX,CL
  211.     mov    dh,al            ;save it in DH
  212.  
  213.     mov    ax,bx            ;Get the time back
  214.     and    AX,Mask    Min        ;Get min part
  215.     mov    CL,Min            ;Bits to shift
  216.     shr    ax,cl
  217.     mov    dl,al            ;save it
  218.     mov    ax,bx            ;get the time back
  219.     and    ax,Mask Sec        ;get seconds part
  220.  
  221.     mov    cx,dx            ;CX needs hours/minutes
  222.     xor    dx,dx            ;no hundredths of seconds avail
  223.     mov    dh,al            ;DH needs seconds
  224.  
  225.     pop    bx            ;restore
  226.     ret
  227. GetTime    ENDP
  228.  
  229. fpath    db    '%:\',0        ;file path for temp file (root)
  230.     db    12 dup(0)    ;room for appended temp filename
  231.  
  232. CSEG    ENDS
  233.     END    NetTime
  234.